package org.insatandroidclub.animalsforkids.utils;

import java.util.ArrayList;
import java.util.List;

import org.insatandroidclub.animalsforkids.model.Animal;

import android.widget.Button;

public class MiscFunctions 
{

	public static void initButtonStrings(int currentIndex,List<Animal> animalsCarousel,Button button1,Button button2,Button button3)
	{
		int done = 0;
		int lower = 0;
		int higher = animalsCarousel.size();
		int random = 0;
		int whichbutton = 0;
        boolean btn1istrue = false;
        boolean btn2istrue = false;
        boolean btn3istrue = false;
		
        
        whichbutton = (int)(Math.random() * 3);
		switch (whichbutton) {
		case 0:
		{
			button1.setText(animalsCarousel.get(currentIndex).getName());
			btn1istrue = true;
		}
			break;
		case 1:
		{
			button2.setText(animalsCarousel.get(currentIndex).getName());
			btn2istrue = true;
		}
			break;
		case 2:
		{
			button3.setText(animalsCarousel.get(currentIndex).getName());
			btn3istrue = true;
		}
			break;
		default:
			break;
		}
		
		
		ArrayList<Integer> used = new ArrayList<Integer>();
		while (done != 2)
		{
			random = (int)(Math.random() * (higher-lower)) + lower;
			if ( (random != currentIndex) &&  (!used.contains(random)) )
			{
				used.add(random);
				done++;
			}
		}
		
		
		for (Integer integer : used) 
		{
			if (!btn1istrue)
			{
				btn1istrue = true;
				button1.setText(animalsCarousel.get(integer).getName());
			}
			else if (!btn2istrue)
			{
				btn2istrue = true;
				button2.setText(animalsCarousel.get(integer).getName());
			}
			else if (!btn3istrue)
			{
				btn3istrue = true;
				button3.setText(animalsCarousel.get(integer).getName());
			}
		}
		
		
	}
}
